package com.hhxy.login.service.misc;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

/**
 * @auther:Lu Yao
 * @date:2022/7/1
 * @description:
 **/
@Component
@Slf4j
public class ApplicationService implements ApplicationContextAware, ApplicationListener<ServiceChangeEvent> {

    private  ApplicationContext applicationContext;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext=applicationContext;
    }

    @Override
    public void onApplicationEvent(ServiceChangeEvent serviceChangeEvent) {
        String event = serviceChangeEvent.getEvent();
        log.info(event);
    }

    public void pushEvent(ServiceChangeEvent serviceChangeEvent){
        this.applicationContext.publishEvent(serviceChangeEvent);
    }
}